home *** CD-ROM | disk | FTP | other *** search
Java Source | 2000-09-28 | 4.0 KB | 143 lines | [TEXT/CWIE] |
- import java.awt.*;
- import java.awt.event.*;
- import java.util.Hashtable;
-
- /**
- * An abstract class to implement the core features of a component with
- * button like behavior, and the capability to display several images
- * representing different states of the button.
- */
- public abstract class ImageButton extends Component
- {
- //Declare data members
- //Insert "ImageButton data members"
-
- /**
- * Constructs a default instance of this class.
- */
- public ImageButton()
- {
- //REGISTER_LISTENERS
- //Insert "ImageButton register listeners"
-
- //Initialize state information
- //Insert "ImageButton init state"
- }
-
- /**
- * Gets called when the mouse button is released on this button.
- * @param isMouseInside, if true, the mouse is located inside the button area,
- * if false the mouse is outside the button area.
- */
- protected void handleMouseRelease(boolean isMouseInside)
- {
- //Handle firing an ActionEvent to our listeners if the mouse was released
- //inside the button.
- //Insert "ImageButton handleMouseReleased"
- }
-
- /**
- * Gets called when the mouse crosses into or out of the button area.
- * @param isMouseInside, is true if the mouse is in the button area,
- * false if it is outside.
- * @param isMouseDown, is true if the mouse button is pressed, false if it is not.
- */
- protected abstract void handleRollover(boolean isMouseInside, boolean isMouseDown);
-
- /**
- * Gets called when the mouse button is pressed on this button.
- */
- protected abstract void handleMousePressed();
-
-
- /**
- * Adds an image to the button.
- * @param imagePath, the location of the image resource to use.
- * This path is relative to the location of this class file.
- * @param imageName, the name used to identify the image for later
- * use in this button.
- * @see #removeImage
- */
- public void addImage(String imagePath, String imageName)
- {
- //Handle storing the information in our internal data structure.
- //Insert "ImageButton addImage"
- }
-
- /**
- * Removes an image from the button
- * @param imageName, the identifying name of the image to remove.
- * @see #addImage
- */
- public void removeImage(String imageName)
- {
- //Handle removing the image from our internal data structure.
- //Insert "ImageButton removeImage"
- }
-
- /**
- * Sets the image for the button to use as its current image.
- * @param imageName, the identifying name of the image to use.
- */
- public void setImage(String imageName)
- {
- //Handle locating the image in our internal data structure,
- //setting it as the current image, and repainting the button.
- //Insert "ImageButton setImage"
- }
-
- /**
- * Gets the name of the image currently in use.
- * @return The identifying name of the image being used.
- */
- public String getImage()
- {
- //Return the current image name.
- //Insert "ImageButton getImage"
- }
-
- /**
- * Gets the actual Image Object which is currently being used.
- * @return The java.awt.Image currently in use.
- */
- public Image getImageObject()
- {
- //Return the current image object.
- //Insert "ImageButton getImageObject"
- }
-
-
- //Routines for handling ActionListener management.
- //Insert "ImageButton Action Management"
-
- /**
- * Returns the preferred size of this component.
- * @see #getMinimumSize
- * @see LayoutManager
- */
- public Dimension getPreferredSize()
- {
- //If the current image is not null, then return the size of the image.
- //If it is null, defer to the super class.
- //Insert "ImageButton getPreferredSize"
- }
-
- /**
- * Paints the component. This method is called when the contents
- * of the component should be painted in response to the component
- * first being shown or damage needing repair. The clip rectangle
- * in the Graphics parameter will be set to the area which needs
- * to be painted.
- * @param g the specified Graphics window
- * @see #update
- */
- public void paint(Graphics g)
- {
- //Let the super class draw, then handle drawing the current image.
- //Insert "ImageButton paint"
- }
-
- //Inner class for handing mouse events.
- //Insert "ImageButton Mouse Handling"
- }
-